﻿@using Himall.Model

@model List<Himall.Model.ShippingAddressInfo>
@{
        ViewBag.Title = "收货地址管理";
}
<div class="container">
    <ul class="list-group address">
        <h4 class="custom-title">收货地址管理</h4>
        @foreach (var item in Model)
        {
            <li href="" class="list-group-item">
                <div onclick="ChooseAddr(@item.Id)">
                    <i class="glyphicon glyphicon-ok-@item.Id"></i>
                    <h6>@item.ShipTo <span>@item.Phone</span></h6>
                    <p>@item.RegionFullName+@item.Address</p>
                </div>
                <a class="glyphicon glyphicon-pencil" onclick="EditAddr(@item.Id)"></a>
            </li>
        }
    </ul>
    <footer class="clearfix footer-buy">
        <a class="btn btn-danger" onclick="EditAddr(0)"><i class="glyphicon glyphicon-plus-sign"></i> 新增地址</a>
    </footer>
</div>

<script>
    function ChooseAddr(addId) {
        $(".glyphicon-ok-'"+addId+"'").addClass("active");
        $.post('/'+areaName + '/order/SetDefaultUserShippingAddress',{addId:addId},function(result){
            if(result.success)
            {
                if(QueryString('returnURL')!=null)
                    location.href = decodeURIComponent(QueryString('returnURL'));
            }
        });
    }

    function EditAddr(addId){
        var url=QueryString('returnURL');
        if (!url)
            url=location.href;
        location.href = '/' + areaName + '/order/EditShippingAddress?addressId=' + addId + '&returnURL=' +url;
    }
</script>